struct Task {
    int briefingTime;
    int executionTime;

    Task(int b, int j) : briefingTime(b), executionTime(j) {}
};

#include <vector>
#include <algorithm>

int solve(std::vector<Task> & tasks) {
    std::sort(tasks.begin(), tasks.end(), [](Task const & a, Task const & b){
        return a.executionTime > b.executionTime;
    });
    int ans = 0;
    int totBriefingTime = 0;
    for (auto const & task : tasks) {
        totBriefingTime += task.briefingTime;
        ans = std::max(ans, totBriefingTime + task.executionTime);
    }
    return ans;
}

#include <iostream>

int main() {

    for (int caseCount = 1; ; ++caseCount) {
        int n;

        std::cin >> n;
        if (n == 0) break;

        std::vector<Task> tasks;
        tasks.reserve(n);

        for (int i = 0; i < n; ++i) {
            int b, j;
            std::cin >> b >> j;
            tasks.emplace_back(b, j);
        }

        std::cout << "Case " << caseCount << ": " << solve(tasks) << "\n";
    }
}
